package com.bnyy.medicalHousekeeper.moudle.message.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SizeUtils;
import com.bnyy.common.adapter.BaseNormalListAdapter;
import com.bnyy.medicalHousekeeper.moudle.message.MessageHeaderHelper;
import com.bnyy.message.bean.Contact;
import com.bnyy.message.bean.ContactGroup;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/11/10
 **/
public class Share2ContactAdapter extends BaseNormalListAdapter<Contact, Share2ContactAdapter.ViewHolder> {

    private int padding;

    public Share2ContactAdapter(Context context) {
        super(context);
        padding = SizeUtils.dp2px(5);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RelativeLayout relativeLayout = new RelativeLayout(mContext);
        relativeLayout.setPadding(0, padding, padding, padding);
        return new ViewHolder(relativeLayout);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        Contact data = getData(position);
        if (data instanceof ContactGroup) {
            ContactGroup contactGroup = (ContactGroup) data;
            MessageHeaderHelper.setHeader(mContext, holder.rlHeaders, contactGroup.getImgs());
        } else {
            MessageHeaderHelper.setHeader(mContext, holder.rlHeaders, data.getUser_img());
        }
    }

    public static class ViewHolder extends BaseNormalListAdapter.ViewHolder {
        RelativeLayout rlHeaders;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            rlHeaders = (RelativeLayout) itemView;
        }
    }
}
